home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / misc / football / user / updateschedulescores.rexx < prev    next >
OS/2 REXX Batch file  |  1999-02-03  |  10KB  |  384 lines

  1. /* ***********************************************************************
  2.  
  3.   UPDATE SCHEDULE FILE PROGRAM FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------------------
  5.                    Copyright  Mark Naughton 1998
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  
  11.  1.0       011098   Created. Found problem where the updates are not
  12.                     successfully made - fixed. Updated messages.
  13.  
  14. **************************************************************************
  15.  
  16. Procedure
  17. ---------
  18.  
  19. 1. Check files exist. Get schedule definition filename from '.df' file.
  20. 2. Read specified schedule definition file.
  21. 3. Read schedules and store dates/weeks.
  22. 4. Give error if the number of teams does not equal the number of lines in
  23.    the schedule file.
  24. 5. Write the dates/weeks to a file then use an external program to sort
  25.    them, writing back to the file.
  26. 6. Read dates into array and delete file.
  27. 7. Format dates array with season start date.
  28. 8. Format and write '.sf' files.
  29. 9. Read all data from Learn (without '*') into an array. Close file.
  30. 10.Open Schedule file and read into an array. Close file.
  31. 11.Update Schedule array with data from Learn but only if a match hasn't
  32.    been played.
  33. 12.Write to Schedule file. Close file. Exit.
  34.  
  35. ************************************************************************** */
  36. PARSE ARG league_file
  37.  
  38. version      = 1
  39. league_file  = "Data/" || strip(league_file)
  40. input_file   = '.df'
  41. input2_file  = '.schd'
  42. input3_file  = '.sflearn'
  43. output_file  = '.sf'
  44. title        = '*LEAGUE_NAME='
  45. autosched    = "*AUTOSCHD="
  46. teams.       = '???'
  47. dateweeks.   = '???'
  48. tdateweeks.  = '???'
  49. schedules.   = '???'
  50. selines.     = '???'
  51. sdlines.     = '???'
  52. autos        = 0
  53. tcount       = 0
  54. ttc          = 0
  55. separator    = '*'
  56. not_played   = '__   __'
  57. months       = "January February March April May June July August September October November December"
  58.  
  59.  
  60. if exists(league_file || input_file) = 0 then exit
  61.  
  62. tcount = 0
  63. if open(datafile,league_file || input_file,'r') then do
  64.    do while ~eof(datafile)
  65.       line = readln(datafile)
  66.       line = strip(line)
  67.       if pos(separator,line) > 0 then do
  68.          if pos(autosched,line) > 0 then do
  69.             autofile = delstr(line,1,10)
  70.             autos = 1
  71.          end
  72.          if pos(title,line) > 0 then do
  73.             parse var line "*LEAGUE_NAME=" league_title
  74.             league_title = strip(league_title)
  75.          end
  76.        end
  77.        if pos(separator,line) = 0 & line ~="" then do
  78.             tcount = tcount + 1
  79.             teams.tcount = line
  80.        end
  81.    end
  82.    close(datafile)
  83. end
  84. else do
  85.    say
  86.    say "ERROR :    (UpdateScheduleScores)"
  87.    say
  88.    say "Cannot open '"league_file || input_file"' for reading."
  89.    exit
  90. end
  91.                                           /* Automatic Schedule creation */
  92. if autos = 1 then do
  93.  
  94.    if exists("Data/"autofile||input2_file) = 0 then do
  95.       say
  96.       say "ERROR :    (UpdateScheduleScores)"
  97.       say
  98.       say "Cannot find 'Data/"autofile||input2_file"'."
  99.       exit
  100.    end
  101.  
  102.    ct = 0
  103.    sct= 0
  104.    weeks = 0
  105.    dates = 0
  106.  
  107.    if open(datafile,"Data/"autofile||input2_file,'r') then do
  108.       do while ~eof(datafile)
  109.          line = readln(datafile)
  110.          if pos("*WEEKS",line) then do
  111.             weeks=1
  112.          end
  113.          if pos("*DATES=",line) then do
  114.             startdate=substr(line,8,8)
  115.             dates = 1
  116.          end
  117.          if line ~= '' & pos(separator,line) = 0 then do
  118.             sct = sct + 1
  119.             schedules.sct = line
  120.             counter = words(line)
  121.             do i=1 to counter
  122.                sdate = word(line,i)
  123.                if sdate = 0 then
  124.                   iterate
  125.                if ct = 0 then do
  126.                   ct = ct + 1
  127.                   dateweeks.ct = sdate
  128.                end
  129.                else do
  130.                   ij = 0
  131.                   do j=1 to ct
  132.                      if sdate = dateweeks.j then do
  133.                         ij = 1
  134.                         leave
  135.                      end
  136.                   end
  137.                   if ij = 0 then do
  138.                      ct = ct + 1
  139.                      dateweeks.ct = sdate
  140.                   end
  141.                end
  142.             end
  143.          end
  144.       end
  145.       close(datafile)
  146.    end
  147.    else do
  148.       say
  149.       say "ERROR :    (UpdateScheduleScores)"
  150.       say
  151.       say "Cannot find 'Data/"autofile||input2_file"' for reading."
  152.       exit
  153.    end
  154.  
  155.    if tcount ~= sct then do
  156.       say
  157.       say "ERROR :    (UpdateScheduleScores)"
  158.       say
  159.       say "The schedule definition file specified only has "sct" scheduled"
  160.       say "teams whereas there are "tcount" teams in the league."
  161.       say
  162.       say "Creation of files aborted. Re-specify correct schedule."
  163.       say
  164.       say "Definition file    :  "league_file||input_file
  165.       say "Schedule Def. file :  Data/"autofile||input2_file
  166.       say
  167.       exit
  168.    end
  169.  
  170.    if open(datafile2,"RAM:schd.temp",'w') then do
  171.       do j=1 to ct
  172.          writeln(datafile2,dateweeks.j)
  173.       end
  174.       close(datafile2)
  175.    end
  176.    else do
  177.       say
  178.       say "ERROR :    (UpdateScheduleScores)"
  179.       say
  180.       say "Cannot create temporary file in RAM:."
  181.       exit
  182.    end
  183.  
  184.    if weeks = 1 then
  185.       address command 'sort RAM:schd.temp RAM:schd.temp'
  186.    if dates = 1 then
  187.       address command 'Exec/SortWkDts'
  188.  
  189.    if open(datafile2,"RAM:schd.temp",'r') then do
  190.       do j=1 to ct
  191.          dateweeks.j = readln(datafile2)
  192.       end
  193.       close(datafile2)
  194.    end
  195.    else do
  196.       say
  197.       say "ERROR :    (UpdateScheduleScores)"
  198.       say
  199.       say "Cannot find temporary file in RAM:."
  200.       exit
  201.    end
  202.  
  203.    address command 'delete >NIL: RAM:schd.temp'
  204.  
  205.    if dates = 1 then do
  206.       do j=1 to ct
  207.          if dateweeks.j = startdate then do
  208.             do i=1 to j-1
  209.                tdateweeks.i = dateweeks.i
  210.             end
  211.             k = 1
  212.             do i=j to ct
  213.                dateweeks.k = dateweeks.i
  214.                k = k + 1
  215.             end
  216.             do i=1 to j-1
  217.                dateweeks.k = tdateweeks.i
  218.                k = k + 1
  219.             end
  220.             leave
  221.          end
  222.       end
  223.    end
  224.  
  225.    if open(outfile,league_file || output_file,"w") then do
  226.       writeln(outfile,"*")
  227.       writeln(outfile,"**" league_title)
  228.       writeln(outfile,"*")
  229.       writeln(outfile,"*")
  230.  
  231.       matches = 0
  232.       do i=1 to ct
  233.          if weeks = 1 then
  234.             writeln(outfile,"*Week: "dateweeks.i)
  235.          if dates = 1 then do
  236.             mnth = substr(dateweeks.i,3,2)
  237.             ndate= substr(dateweeks.i,5,4)||mnth||substr(dateweeks.i,1,2)
  238.             weekd= date('w',ndate,'s')
  239.             writeln(outfile,"*Date: "weekd" "substr(dateweeks.i,1,2)" "word(months,mnth)" "substr(dateweeks.i,5,4))
  240.          end
  241.          writeln(outfile,"*")
  242.          do k=1 to counter
  243.             do j=1 to counter
  244.                sdate = word(schedules.k,j)
  245.                if dateweeks.i = sdate then do
  246.                   writech(outfile,left(teams.k,30))
  247.                   writeln(outfile," __   __ " teams.j)
  248.                   matches = matches + 1
  249.                   leave
  250.                end
  251.             end
  252.          end
  253.          writeln(outfile,"*")
  254.       end
  255.       writeln(outfile,"*")
  256.       close(outfile)
  257.    end
  258.    else do
  259.       say
  260.       say "ERROR :    (UpdateScheduleScores)"
  261.       say
  262.       say "Unable to write to '"league_file || output_file"'."
  263.       exit
  264.    end
  265. end
  266. else do
  267.    say
  268.    say "ERROR :    (UpdateScheduleScores)"
  269.    say
  270.    say "This definition file, "league_file||input_file", does not use a"
  271.    say "schedule definition file. It is not automatically scheduled so"
  272.    say "this will not work. Use 'UpdateScores' instead."
  273.    say
  274.    exit
  275. end
  276.  
  277. secount = 0
  278. if open(datafile,league_file||input3_file,'r') then do
  279.    do while ~eof(datafile)
  280.       line = readln(datafile)
  281.       line = strip(line)
  282.       if pos(separator,line) = 0 & line ~= "" then do
  283.          secount         = secount + 1
  284.          selines.secount = line
  285.       end
  286.    end
  287.    close(datafile)
  288. end
  289. else do
  290.    say
  291.    say "ERROR :    (UpdateScheduleScores)"
  292.    say
  293.    say "Cannot open '"league_file||input3_file"' for re-reading."
  294.    exit
  295. end
  296. say "Updates to make: "secount
  297.  
  298. sdcount = 0
  299. if open(datafile3,league_file || output_file,'r') then do
  300.    do while ~eof(datafile3)
  301.        line = readln(datafile3)
  302.        line = strip(line)
  303.        if line ~= "" then do
  304.           sdcount         = sdcount + 1
  305.           sdlines.sdcount = line
  306.        end
  307.    end
  308.    close(datafile3)
  309. end
  310. else do
  311.    say
  312.    say "ERROR :    (UpdateScheduleScores)"
  313.    say
  314.    say "Cannot open '"league_file || output_file"' for reading."
  315.    exit
  316. end
  317.  
  318. i    = 0
  319. done = 0
  320.  
  321. say "SDCount = "sdcount
  322. do k=1 to secount
  323.    say ">"selines.k"<"
  324. end
  325.  
  326. do j=1 to sdcount
  327.    shome = strip(substr(sdlines.j,1,30))
  328.    saway = strip(substr(sdlines.j,41,30))
  329.    do i=1 to secount
  330.       home  = strip(substr(selines.i,1,30))
  331.       away  = strip(substr(selines.i,41,30))
  332.       if shome = home & saway = away & pos(not_played,sdlines.j) > 0 then do
  333.          sdlines.j = selines.i
  334.          say ">>"selines.i"<<"
  335.          k = k + 1
  336.          leave
  337.       end
  338.    end
  339.    if k = secount then leave
  340. end
  341. /*
  342.    if done = 0 then do
  343.       i = i + 1
  344.       if i > secount then leave
  345.       home  = strip(substr(selines.i,1,30))
  346.       away  = strip(substr(selines.i,41,30))
  347.       done = 1
  348.    end
  349.    if pos(separator,sdlines.j) = 0 then do
  350.       shome = strip(substr(sdlines.j,1,30))
  351.       saway = strip(substr(sdlines.j,41,30))
  352.       if shome = home & saway = away & pos(not_played,sdlines.j) > 0 then do
  353.          sdlines.j = selines.i
  354.          say ">>"selines.i"<<"
  355.          done = 0
  356.       end
  357.    end
  358. */
  359.  
  360. say "Amendments made: "k" ("i")"
  361.  
  362. if open(datafile3,league_file || output_file,'w') then do
  363.    do j=1 to sdcount
  364.       writeln(datafile3,sdlines.j)
  365.    end
  366.    close(datafile3)
  367. end
  368. else do
  369.    say
  370.    say "ERROR :    (UpdateScheduleScores)"
  371.    say
  372.    say "Cannot open '"league_file || output_file"' for writing."
  373.    exit
  374. end
  375.  
  376. say
  377. say "SUCCESS :    (UpdateScheduleScores)"
  378. say
  379. say "This program has taken the schedule definition file,"
  380. say "'Data/"autofile||input2_file"' and the results from '"league_file||input3_file"'"
  381. say "and has recreated '"league_file||output_file"'."
  382. say
  383.  
  384. exit